Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add baking script for archival bakes #4502

Merged
merged 27 commits into from
Feb 11, 2025
Merged

Conversation

marcelgerber
Copy link
Member

@marcelgerber marcelgerber commented Jan 29, 2025

This implements milestone 1 of #4434: correctly referencing assets in an archival bake.

It:

  • content-hashes
    • JS & CSS assets
    • dods.json files
    • Data & metadata files
  • puts them into staticAssetMap and runtimeAssetMap, respectively
  • makes sure these are both propagated to the correct function calls

To run this locally, run the following:

yarn buildViteSite # builds JS & CSS into dist/ folder
VITE_PREVIEW=true npx tsx --tsconfig tsconfig.tsx.json ./baker/buildLocalArchivalBake.ts --latestDir # build the latest archival build into archive/ dir
# VITE_PREVIEW is needed for now to correctly reference JS assets
npx serve archive/ # serves on localhost:3000

You can then navigate to http://localhost:3000/latest/grapher/life-expectancy to view the page.

@owidbot
Copy link
Contributor

owidbot commented Jan 29, 2025

Quick links (staging server):

Site Dev Site Preview Admin Wizard Docs

Login: ssh owid@staging-site-archival-baker

SVG tester:

Number of differences (default views): 0 ✅
Number of differences (all views): 0 ✅

Edited: 2025-02-11 11:16:52 UTC
Execution time: 1.19 seconds

@marcelgerber marcelgerber force-pushed the archival-baker branch 3 times, most recently from 4ffb030 to 8ce7d67 Compare February 4, 2025 17:34
@marcelgerber marcelgerber requested a review from rakyi February 4, 2025 17:34
@marcelgerber marcelgerber marked this pull request as ready for review February 4, 2025 17:35
Copy link
Contributor

@rakyi rakyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Couple of notes:

  • Loading the whole file into memory before hashing might consume a lot of memory when we start doing full archival bakes. I guess it's fine to solve this (by switching to streams) once we hit the problem in practice, so this is more of an FYI to keep it in mind.
  • Since the asset map is never gonna change, we can save ourselves quite a bit of trouble by attaching it to window and reading it from there every time we need to check it, instead of passing it via props. At least for the runtime map, might not be true for the static. Or am I missing something?

serverUtils/hash.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want errors from this script reported in Sentry. See e.g. baker/algolia/indexChartsToAlgolia.ts for an example on how to do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unresolving, since I don't see the import of serverUtils/instrument.js at the top. You can copy what's in indexChartsToAlgolia.ts.

baker/buildLocalArchivalBake.ts Outdated Show resolved Hide resolved
@marcelgerber
Copy link
Member Author

  • Since the asset map is never gonna change, we can save ourselves quite a bit of trouble by attaching it to window and reading it from there every time we need to check it, instead of passing it via props. At least for the runtime map, might not be true for the static. Or am I missing something?

Yep, you're absolutely right. I considered doing this, and then didn't end up doing it, but for no good reason really.

I've now changed things around and am putting these under window._OWID_RUNTIME_ASSET_MAP.

Copy link
Contributor

@rakyi rakyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM except the missing instrumentation import.

@marcelgerber marcelgerber merged commit 6f6d734 into master Feb 11, 2025
15 of 18 checks passed
@marcelgerber marcelgerber deleted the archival-baker branch February 11, 2025 15:59
Copy link

sentry-io bot commented Feb 11, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ Error: Data page with slug "antibiotic-use-in-livestock-in-europe" is using "Antibiotics" as its primary tag, which we are unable to resolve to a tag in the grapher DB getPrimaryTopic(DatapageHelpers.ts) View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants